<template>
	<u-sticky bgColor="#fff">
		<view class="">
			<u-navbar :title="title" :autoBack="false">
				<view class="u-nav-slot" slot="left">
					<u-icon name="arrow-left" size="38" @click="backClick"></u-icon>
					<u-line direction="column" :hairline="false" length="32" margin="0 8px"></u-line>
					<u-icon name="home" size="45" style="color: #fff;" @click="homeClick"></u-icon>
				</view>
			</u-navbar>
		</view>
		<view v-if="isSearch" class="" style="padding: 20rpx 28rpx;display: flex;background-color: #fff;border-bottom: 1px solid #eee;">
			<view class="" style="flex: 1; margin-right: 28rpx;">
				<u-search :placeholder="searchTitle" v-model="keyword" height="60" :showAction="false" searchIconSize="48"
					bgColor="#f5f5f5" @search="goSearch" shape="square"></u-search>
			</view>
			<u-icon name="list" size="48" color="#000" @click="openSideBar"></u-icon>
		</view>
		<view v-if="isTab" class="tabs">
			<u-tabs :current="tabIndex" :list="tabs" lineHeight="6rpx" lineColor="#fd7400"
				:inactiveStyle="{color: '#000'}" :activeStyle="{color: '#fd7400'}" @change="changeTab"
				:scrollable="false"></u-tabs>
		</view>
	</u-sticky>
</template>

<script>
	export default {
		name:"headassy",
		props: {
			// 标题
			title: {
				type: String,
				default: ' ',
			},
			// 是否存在搜索栏
			isSearch: {
				type: Boolean,
				default: true,
			},
			searchTitle: {
				type: String,
				default: '请输入搜索内容',
			},
			// 是否存在导航列表
			isTab: {
				type: Boolean,
				default: true,
			},
			tabIndex: {
				type: String,
				default: '0',
			},
			tabs: {
				type: Array,
				default: [],
			},
		},
		data() {
			return {
				keyword: '',
			};
		},
		methods: {
			
			// 搜索
			goSearch() {
				this.$emit('goSearch',this.keyword);
			},
			
			// 打开侧边栏
			openSideBar() {
				this.$emit('openSideBar');
			},
			
			// 切换tab
			changeTab(item) {
				this.$emit('changeTab',item);
			},
			
			// 回到上一页
			backClick(e){
				let pages = getCurrentPages();
				console.log('pages', pages)
				if(pages.length > 1){
					uni.navigateBack();
				}else{
					uni.switchTab({
						url: '/pages/index/index'
					});
				}
			},
			// 回到首页
			homeClick(e){
				uni.switchTab({
					url: '/pages/index/index'
				});
			},
			
		}
	}
</script>
	
<style lang="scss">
	
</style>